/**   
* @Title: OtherContentListAdapter.java 
* @Description: TODO
* @author Mengting Lu   
* @date 2015年8月5日 下午5:57:45 
*/
package com.shanghaionstar.user.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.base.CommonAdapter;
import com.onstar.cn.framework.base.CommonViewHolder;
import com.onstar.cn.more.entity.ContentHeaderType;
import com.shanghaionstar.R;

import java.util.List;

/**
 * @ClassName: OtherContentListAdapter
 * @Description: TODO
 * @author Mengting Lu
 * @date 2015年8月5日 下午5:57:45
 */
public class OtherContentListAdapter extends CommonAdapter<ContentHeaderType> {
	private Context mcontext;

	private List<ContentHeaderType> contentHeaderList;
	private ImageLoader imageLoader = ImageLoader.getInstance();
	private DisplayImageOptions options;

	/**
	 * @Description: TODO
	 * @author Mengting Lu
	 * @date 2015年9月2日 下午2:19:24
	 */
	public OtherContentListAdapter(List<ContentHeaderType> datas, Context context) {
		super(datas, context);
		mcontext = context;
		contentHeaderList = datas;
		options = new DisplayImageOptions.Builder().showStubImage(0).showImageForEmptyUri(0).showImageOnFail(0)
				.resetViewBeforeLoading(true).cacheOnDisc(true).imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
				.bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(100)).build();
	}

	/**
	 * (non-Javadoc)
	 * <p>
	 * Title: getView
	 * </p>
	 * <p>
	 * Description:
	 * </p>
	 * 
	 * @param position
	 * @param viewHolder
	 * @see com.onstar.cn.framework.base.CommonAdapter#getView(int,
	 *      com.onstar.cn.framework.base.CommonViewHolder)
	 */
	@Override
	public void getView(int position, CommonViewHolder viewHolder) {
		ViewHolder holder = (ViewHolder) viewHolder;
		ContentHeaderType headerType = contentHeaderList.get(position);
		String titleString = headerType.getTitle();
		if (!CommonUtil.isNull(headerType.getIcon())) {
//			String[] array = titleString.split(";");
			holder.fwjs_title_iv.setVisibility(View.VISIBLE);
//			holder.story_title_text_id.setText(array[1]);
			holder.story_title_text_id.setText(titleString);
			imageLoader.displayImage(headerType.getIcon(), holder.fwjs_title_iv, options);
		} else {
			holder.fwjs_title_iv.setVisibility(View.GONE);
			holder.story_title_text_id.setText(titleString);
		}
	}

	/**
	 * (non-Javadoc)
	 * <p>
	 * Title: layoutId
	 * </p>
	 * <p>
	 * Description:
	 * </p>
	 *
	 * @return
	 * @see com.onstar.cn.framework.base.CommonAdapter#layoutId()
	 */
	@Override
	public int layoutId() {
		return R.layout.guide_list_item;
	}

	/**
	 * (non-Javadoc)
	 * <p>
	 * Title: getViewHolder
	 * </p>
	 * <p>
	 * Description:
	 * </p>
	 *
	 * @return
	 * @see com.onstar.cn.framework.base.CommonAdapter#getViewHolder()
	 */
	@Override
	public CommonViewHolder getViewHolder() {
		return new ViewHolder();
	}

	private class ViewHolder extends CommonViewHolder {
		@FindViewById
		ImageView fwjs_title_iv;
		@FindViewById
		TextView story_title_text_id;

	}

}
